class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs)
    {
        int hash[5] = { 0 };
        unordered_map<char, int> tmp;
        const char* t = "croak";
        for (int i = 0; i < 5; i++)
        {
            tmp[t[i]] = i;
        }
        for (auto x : croakOfFrogs)
        {
            if (x == 'c')
            {
                if (hash[4] != 0) hash[4]--;
                hash[0]++;
            }
            else
            {
                if (hash[tmp[x] - 1] == 0)return -1;
                hash[tmp[x]]++;
                hash[tmp[x] - 1]--;
            }
        }
        for (int i = 0; i < 4; i++)
        {
            if (hash[i] != 0)return -1;
        }
        return hash[4];

    }
};